package com.dkcrow.spring.transaction.config;

import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.EnableLoadTimeWeaving;
import org.springframework.context.annotation.EnableLoadTimeWeaving.AspectJWeaving;
import org.springframework.context.annotation.ImportResource;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

@Configurable
//@EnableTransactionManagement(mode=AdviceMode.ASPECTJ,order = 0)
//@EnableLoadTimeWeaving(aspectjWeaving=AspectJWeaving.ENABLED)
@ComponentScan(
		basePackages = "com.dkcrow.spring"
		,useDefaultFilters = false
		,includeFilters = {@ComponentScan.Filter(Service.class),@ComponentScan.Filter(Repository.class)}
		)
@ImportResource(value="classpath:/spring/*-context.xml")
public class RootConfig {
	
	@Bean
	public String test(){
		return "test";
	}
	
	/**
	 * 
	@Autowired private DataSource dataSource;
	@Autowired SqlSessionFactory sqlSessionFactory;
	@Autowired DataSourceTransactionManager txManager;
	
	@Bean
	public BasicDataSource dataSource(){
		BasicDataSource dataSource = new BasicDataSource();
		dataSource.setDriverClassName("com.mysql.jdbc.Driver");
		dataSource.setUrl("jdbc:mysql://localhost:3306/mydb");
		dataSource.setUsername("dkcrow");
		dataSource.setPassword("dkcrow00");
		dataSource.setInitialSize(15);
		dataSource.setMaxActive(15);
		dataSource.setMaxIdle(15);
		dataSource.setMinIdle(2);
		return dataSource;
	}
	
	@Bean
	public DataSourceTransactionManager txManager(){
		DataSourceTransactionManager txManager = new DataSourceTransactionManager();
		txManager.setDataSource(this.dataSource);
		return txManager;
	}
	
	@Bean
	public AnnotationTransactionAspect transactionAspect(){
		AnnotationTransactionAspect txAspect = AnnotationTransactionAspect.aspectOf();
		txAspect.setTransactionManager(txManager);
		return txAspect;
	}
	
//	@Bean
//	public JdbcTemplate jdbcTemplate(){
//		JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
//		return jdbcTemplate;
//	}
	
	@Bean 
	public SqlSessionFactoryBean sqlSessionFactory(){
		SqlSessionFactoryBean sf = new SqlSessionFactoryBean();
		sf.setDataSource(dataSource);
		Resource[] mapperLocations = new Resource[]{new ClassPathResource("/mapper/user.sql.xml")};
		sf.setMapperLocations(mapperLocations);
		return sf;
	}
	
	@Bean
	public SqlSessionTemplate sqlSession(){
		SqlSessionTemplate ss = new SqlSessionTemplate(sqlSessionFactory);
		return ss;
	}
	*/
}
